/*
 * gui.c
 *
 *  Created on: 2011-3-13
 *      Author: zj
 */
#include "stdafx.h"
#include <string.h>
#include "SWidget.h"
#include "apptypedef.h"
#include "syscfg.h"
#include "MenuIf.h"


//#if defined(__cplusplus)
//extern "C" {     /* Make sure we have C-declarations in C++ programs */
//#endif

char lcd_sim_mem[LCD_SIM_WIDTH * LCD_SIM_HEIGHT / 8];
volatile static char key = 0;

/////////////////////////////////////////////////////////////////////
void bak_lcd_disp(char *disp)
{
    memcpy(disp + LCD_SIM_WIDTH * 2, (char*)lcd_sim_mem + LCD_SIM_WIDTH * 2, sizeof(lcd_sim_mem) - LCD_SIM_WIDTH * 4);
}
void res_lcd_disp(char *disp)
{
    WIDGET_Lock();
    memcpy((char*)lcd_sim_mem + LCD_SIM_WIDTH * 2, disp + LCD_SIM_WIDTH * 2, sizeof(lcd_sim_mem) - +LCD_SIM_WIDTH * 4);
    WIDGET_UnLock();
}
void clear_screen(void)
{
    WIDGET_Lock();
    memset((char*)lcd_sim_mem, 0, sizeof(lcd_sim_mem));
    WIDGET_UnLock();
}
extern unsigned int SysGetKey();
int sys_getchar(void)
{
   // unsigned int newKey = SysGetKey();

    return 0;
}

void set_pix(int x, int y, int value)
{
    x %= LCD_SIM_WIDTH;
    y %= LCD_SIM_HEIGHT;

    //lcd_sim_mem[y * LCD_SIM_WIDTH / 8 + x / 8] &= ~(1 << (x % 8));
    //lcd_sim_mem[y * LCD_SIM_WIDTH / 8 + x / 8] |= ((value & 1) << (x % 8));
    lcd_sim_mem[y * LCD_SIM_WIDTH_BYTE + (x >> 3)] &= ~(1 << (7 - (x & 0x07)));
    lcd_sim_mem[y * LCD_SIM_WIDTH_BYTE + (x >> 3)] |= ((value & 1) << (7 - (x & 0x07)));

}

//#if defined(__cplusplus)
//}
//#endif

extern int g_iLcdStartClick;

void LcdRefresh()
{
    //Debug(DB_CRITICAL, ("############display: LcdRefresh!\n"));
    //WIDGET_Lock();
    //int xx = GetClick();

    //if ((g_iLcdStartClick + 60) < xx)
    {
    	RefreshMenu((BYTE*)lcd_sim_mem);
    }
    //WIDGET_UnLock();
}


void BlightOn(bool fOn)
{

}
